﻿/*
 * @autor: hector
 * @date: 26/07/2012
 * @project: Merge2UnsortedArraysWithoutDuplicates
 */

using System;
using System.Diagnostics;

namespace Merge2UnsortedArraysWithoutDuplicates
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            //int[] array1 = GetArray(25);
            //for (int i = 0; i < array1.Length; i++)
            //    Console.Write(" {0} ", array1[i]);

            //Console.WriteLine();

            //int[] array2 = GetArray(20);
            //for (int i = 0; i < array2.Length; i++)
            //    Console.Write(" {0} ", array2[i]);
            
            //Console.WriteLine();
            //int[] array = { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            int[] array = { 1, 4, 2, 3, 1, 5, 6, 7, 8, 9 };
            //int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 };
            sw.Start();
            //int[] result = array1.MergeWithOutDuplicates(array2);
            //result = result.BubbleSort();

            //int[] result = array1.MergeWithOutDuplicatesOptimized(array2);


            array.FindDuplicatesOptimized();
            //array.FindDuplicates();
            
            sw.Stop();

            							


            //for (int i = 0; i < result.Length; i++)
            //    Console.Write(" {0} ", result[i]);

            Console.WriteLine();

            Console.WriteLine("Elapsed time {0} ticks", sw.ElapsedTicks);
            Console.ReadLine();
        }

        private static int[] GetArray(int length)
        {
            int[] arr = new int[length];

            Random r = new Random(length);

            for (int i = 0; i < length; i++)
            {
                arr[i] = r.Next(0,10);
            }

            return arr;
        }

        private static int? FindDuplicatedValueFromArray(int[] array)
        {
            for (int i = 0; i < array.Length; i++)
            {
                for (int j = i + 1; j < array.Length; j++)
                {
                    if (array[i] == array[j])
                    {
                        return array[i];
                    }
                }
            }
            //In case we don't have a repeated value. 								
            return null;
        }				
    }
}
